package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import entity.User;
import groupInformation.Invivation;
import serviceImpl.invitation;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "ShowInvitationServlet", value = "/ShowInvitationServlet")
public class ShowInvitationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");

        PrintWriter out =response.getWriter();

        User user =(User) request.getSession().getAttribute("user");
        invitation in= new invitation();
        List<Invivation> invivations = in.selectInvi(user);

        ObjectMapper mapper = new ObjectMapper(); //Jackson的核心类
        String json = mapper.writeValueAsString(invivations);
        System.out.println("邀请："+json);

        out.print(json);
    }
}
